package com.demo.system.controller;

import com.demo.common.entity.ChatRoom;
import com.demo.common.entity.ChatRoomMember;
import com.demo.common.entity.vo.ChatRoomMemberVO;
import com.demo.common.response.Result;
import com.demo.system.service.ChatRoomMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聊天室成员表(ChatRoomMember)控制器
 *
 * @author why
 * @since 2025-09-23 10:12:42
 */
@RestController
@RequestMapping("/chat_room_member")
@CrossOrigin
public class ChatRoomMemberController {

    @Autowired
    private ChatRoomMemberService chatRoomMemberService;


    @GetMapping("/user/{userId}")
    public Result<List<ChatRoomMemberVO>> findByUserId(@PathVariable("userId") String userId) {
        return chatRoomMemberService.listRoomByUserId(userId);
    }


    @PostMapping("/join/{userId}/{roomId}")
    public Result join(@PathVariable("userId") Long userId, @PathVariable("roomId") Long roomId) {
        return chatRoomMemberService.joinChatRoom(userId, roomId);
    }


    @GetMapping("/user/no_join/{userId}")
    public Result<List<ChatRoom>> findOtherRoomByUserId(@PathVariable("userId") String userId) {
        return chatRoomMemberService.findOtherRoomByUserId(userId);
    }


}
